package com.stylefeng.guns.modular.pay.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.pay.model.MchReg;
import com.stylefeng.guns.modular.pay.model.NotifyRecord;
import com.stylefeng.guns.modular.pay.service.INotifyRecordService;

/**
 * 通知记录控制器
 *
 * @author fengshuonan
 * @Date 2018-08-24 15:20:35
 */
@Controller
@RequestMapping("/notifyRecord")
public class NotifyRecordController extends BaseController {

    private String PREFIX = "/pay/notifyRecord/";

    @Autowired
    private INotifyRecordService notifyRecordService;

    /**
     * 跳转到通知记录首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "notifyRecord.html";
    }

    /**
     * 跳转到添加通知记录
     */
    @RequestMapping("/notifyRecord_add")
    public String notifyRecordAdd() {
        return PREFIX + "notifyRecord_add.html";
    }

    /**
     * 跳转到修改通知记录
     */
    @RequestMapping("/notifyRecord_update/{notifyRecordId}")
    public String notifyRecordUpdate(@PathVariable Integer notifyRecordId, Model model) {
        NotifyRecord notifyRecord = notifyRecordService.selectById(notifyRecordId);
        model.addAttribute("item",notifyRecord);
        LogObjectHolder.me().set(notifyRecord);
        return PREFIX + "notifyRecord_edit.html";
    }

    /**
     * 获取通知记录列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(NotifyRecord notifyRecord) {
    	 Page<NotifyRecord> page = new PageFactory<NotifyRecord>().defaultPage();
         List<NotifyRecord> result = notifyRecordService.list(page,notifyRecord);
         page.setRecords(result);
         return super.packForBT(page);
    }

    /**
     * 新增通知记录
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(NotifyRecord notifyRecord) {
        notifyRecordService.insert(notifyRecord);
        return SUCCESS_TIP;
    }

    /**
     * 删除通知记录
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer notifyRecordId) {
        notifyRecordService.deleteById(notifyRecordId);
        return SUCCESS_TIP;
    }

    /**
     * 修改通知记录
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(NotifyRecord notifyRecord) {
        notifyRecordService.updateById(notifyRecord);
        return SUCCESS_TIP;
    }

    /**
     * 通知记录详情
     */
    @RequestMapping(value = "/detail/{notifyRecordId}")
    @ResponseBody
    public Object detail(@PathVariable("notifyRecordId") Integer notifyRecordId) {
        return notifyRecordService.selectById(notifyRecordId);
    }
}
